package cn.snmp.mutual.uk.stack;

public class Varbind {
    private static final String version_id = "@(#)$Id: Varbind.java,v 3.10 2007/10/17 10:47:47 birgita Exp $ Copyright Westhawk Ltd";
    private AsnObjectId name;
    private AsnObject value;

    public Varbind(final Varbind var) {
        this.name = var.name;
        this.value = var.value;
    }

    public Varbind(final String Oid) {
        this(new AsnObjectId(Oid), new AsnNull());
    }

    public Varbind(final AsnObjectId Oid) {
        this(Oid, new AsnNull());
    }

    public Varbind(final String Oid, final AsnObject val) {
        this(new AsnObjectId(Oid), val);
    }

    public Varbind(final AsnObjectId Oid, final AsnObject val) {
        this.name = Oid;
        this.value = val;
    }

    Varbind(final AsnSequence vb) throws IllegalArgumentException {
        final Object obj = vb.getObj(0);
        if (obj instanceof AsnObjectId) {
            this.name = (AsnObjectId) obj;
            this.value = vb.getObj(1);
            return;
        }
        String msg = "First object should be AsnObjectId, but is ";
        if (obj != null) {
            msg += obj.getClass().getName();
        } else {
            msg += "null";
        }
        throw new IllegalArgumentException(msg);
    }

    public AsnObjectId getOid() {
        return this.name;
    }

    public AsnObject getValue() {
        return this.value;
    }

    Object setValue(final AsnSequence vb) throws IllegalArgumentException {
        final Varbind tmp = new Varbind(vb);
        this.name = tmp.name;
        return this.value = tmp.value;
    }

    @Override
    public String toString() {
        return this.name.toString() + ": " + this.value.toString();
    }
}
